<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="redis," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />






<meta name="description" content="redisredis是一个开源的、使用C语言编写的、支持网络交互的、可基于内存也可持久化的Key-Value数据库。">
<meta property="og:type" content="article">
<meta property="og:title" content="Redis 操作入门">
<meta property="og:url" content="https://my.oschina.net/u/588736/blog/2015/10/10/redis_oper_abc/index.html">
<meta property="og:site_name" content="晚来风">
<meta property="og:description" content="redisredis是一个开源的、使用C语言编写的、支持网络交互的、可基于内存也可持久化的Key-Value数据库。">
<meta property="og:updated_time" content="2016-11-28T09:56:24.969Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Redis 操作入门">
<meta name="twitter:description" content="redisredis是一个开源的、使用C语言编写的、支持网络交互的、可基于内存也可持久化的Key-Value数据库。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="https://my.oschina.net/u/588736/blog/2015/10/10/redis_oper_abc/"/>


  <title> Redis 操作入门 | 晚来风 </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">晚来风</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">林花谢了春红，太匆匆。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Redis 操作入门
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-10-10T20:10:33+08:00" content="2015-10-10">
              2015-10-10
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/数据库/" itemprop="url" rel="index">
                    <span itemprop="name">数据库</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="redis"><a href="#redis" class="headerlink" title="redis"></a>redis</h1><p>redis是一个开源的、使用C语言编写的、支持网络交互的、可基于内存也可持久化的Key-Value数据库。</p>
<a id="more"></a>
<p><strong>谁在使用redis：</strong>Blizzard、digg、stackoverflow、github、flickr …  </p>
<h2 id="redis安装"><a href="#redis安装" class="headerlink" title="redis安装"></a>redis安装</h2><p>从<a href="redis.io">Redis官网</a>下载最新版redis-X.Y.Z.tar.gz后解压，然后进入redis-X.Y.Z文件夹后直接make即可，安装非常简单。<br> make成功后会在src文件夹下产生一些二进制可执行文件，包括redis-server、redis-cli等等：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"> $ find . -type f -executable</div><div class="line">./redis-benchmark //用于进行redis性能测试的工具</div><div class="line">./redis-check-dump //用于修复出问题的dump.rdb文件</div><div class="line">./redis-cli //redis的客户端</div><div class="line">./redis-server //redis的服务端</div><div class="line">./redis-check-aof //用于修复出问题的AOF文件</div><div class="line">./redis-sentinel //用于集群管理</div></pre></td></tr></table></figure></p>
<h2 id="启动redis"><a href="#启动redis" class="headerlink" title="启动redis"></a>启动redis</h2><p> 启动redis非常简单，直接./redis-server就可以启动服务端了，还可以用下面的方法指定要加载的配置文件：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./redis-server ../redis.conf</div></pre></td></tr></table></figure></p>
<p>默认情况下，redis-server会以非daemon的方式来运行，且默认服务端口为6379。可以修改配置文件来更改端口。  </p>
<h2 id="使用redis客户端"><a href="#使用redis客户端" class="headerlink" title="使用redis客户端"></a>使用redis客户端</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">//这样来启动redis客户端了</div><div class="line">$ ./redis-cli</div><div class="line"></div><div class="line">//可以指定连接主机和端口</div><div class="line">$./redis-cli -h 10.200.2.8 -p 7788</div><div class="line"></div><div class="line">//查看redis中包含的所有key</div><div class="line">10.200.2.8:7788&gt; keys *</div><div class="line"> 1) &quot;mylist&quot;</div><div class="line"> 2) &quot;mynum&quot;</div><div class="line"></div><div class="line"> //查看key类型</div><div class="line">10.200.2.8:7788&gt; type mylist</div><div class="line">list</div><div class="line"></div><div class="line">//删除key，包括key对应的value</div><div class="line">10.200.2.8:7788&gt; del mynum</div><div class="line">(integer) 1</div><div class="line"></div><div class="line">//通过客户端来关闭redis服务端</div><div class="line">10.200.2.8:7788&gt; shutdown</div></pre></td></tr></table></figure>
<h2 id="redis数据结构"><a href="#redis数据结构" class="headerlink" title="redis数据结构"></a>redis数据结构</h2><p>redis是一种高级的key:value存储系统，其中value支持五种数据类型：</p>
<ul>
<li>字符串（strings）</li>
<li>字符串列表（lists）</li>
<li>字符串集合（sets）</li>
<li>有序字符串集合（sorted sets）</li>
<li>哈希（hashes）  </li>
</ul>
<p><strong>关于key：温馨提示</strong>  </p>
<ol>
<li>key不要太长，尽量少于1024字节，不然会消耗内存，且会降低查询效率。  </li>
<li>key也不要太短，不然可读性会降低。</li>
<li>在一个项目中，key最好使用统一的命名方式，如：user:name:passwd。</li>
</ol>
<h3 id="strings"><a href="#strings" class="headerlink" title="strings"></a>strings</h3><p>先看例子：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">10.200.2.8:7788&gt; set name zhangsan</div><div class="line">OK</div><div class="line">10.200.2.8:7788&gt; get name</div><div class="line">&quot;zhangsan&quot;</div></pre></td></tr></table></figure></p>
<p>设置字符串key为”name”，value为”zhangsan”，使用get来获取指定key的value。<br>二进制是安全的，所以完全可以将一个图片文件的内容作为字串来存储。</p>
<p>还可以通过字符串类型进行数值操作：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">set mynum 2</div><div class="line">get mynum   -&gt; 2</div><div class="line">incr mynum  -&gt; 3</div><div class="line">decr mynum  -&gt; 2</div><div class="line">incrby mynum 3  -&gt; 5</div><div class="line">decrby mynum 4  -&gt; 1</div></pre></td></tr></table></figure></p>
<p>在遇到数值操作时，redis会将字符串类型转换成数值，由于incr等指令本身就具有原子性，所以可以使用incr、incrby、decr等指令实现原子计数的功能，例如：在某种场景下有3个客户端同时取了mynum的值（1），然后对其加一（incr）操作，那么最后mynum的值一定是4。</p>
<h3 id="lists"><a href="#lists" class="headerlink" title="lists"></a>lists</h3><p>redis中的lists在底层实现上是链表而不是数组，对于一个具有上百万个元素的lists来说，在头部和尾部插入一个新的元素，其时间复杂度是常数级的，比如使用LPUSH在10个元素和在上千万个元素的list头部插入新的元素的速度应该相同。但是，链表型的lists定位会比较慢，数组型的lists定位会快的多。<br>lists操作示例：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">//新建一个list叫做mylist，并在列表头部插入元素&quot;1&quot;，回车会返回当前mylist中的元素个数</div><div class="line">10.200.2.8:7788&gt; lpush mylist 1</div><div class="line">(integer) 1</div><div class="line"></div><div class="line">//列出mylist中从编号0到编号-1（倒数第一个）的元素</div><div class="line">10.200.2.8:7788&gt; lrange mylist 0 -1</div><div class="line">1) &quot;1&quot;</div><div class="line"></div><div class="line">10.200.2.8:7788&gt; rpush mylist 3</div><div class="line">(integer) 2</div><div class="line">10.200.2.8:7788&gt; lrange mylist 0 -1</div><div class="line">1) &quot;1&quot;</div><div class="line">2) &quot;3&quot;</div><div class="line">10.200.2.8:7788&gt; lpush mylist 0</div><div class="line">(integer) 3</div><div class="line">10.200.2.8:7788&gt; lrange mylist 0 -1</div><div class="line">1) &quot;0&quot;</div><div class="line">2) &quot;1&quot;</div><div class="line">3) &quot;3&quot;</div></pre></td></tr></table></figure></p>
<p>lists的应用相当广泛，比如：</p>
<ol>
<li>我们可以利用lists来实现一个消息队列，而且可以确保先后顺序，不必像MySQL那样还需要通过ORDER BY来进行排序。</li>
<li>利用LRANGE还可以很方便的实现分页的功能。</li>
<li>在博客系统中，每片博文的评论也可以存入一个单独的list中。</li>
</ol>
<h3 id="sets"><a href="#sets" class="headerlink" title="sets"></a>sets</h3><p>redis的集合，是一种无序集合。操作示例：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div></pre></td><td class="code"><pre><div class="line">//新建集合myset，并添加元素&quot;one&quot;</div><div class="line">10.200.2.8:7788&gt; sadd myset one</div><div class="line">(integer) 1</div><div class="line"></div><div class="line">//统计集合中元素个数</div><div class="line">10.200.2.8:7788&gt; scard myset</div><div class="line">(integer) 1</div><div class="line"></div><div class="line">//查看集合中的元素</div><div class="line">10.200.2.8:7788&gt; smembers myset</div><div class="line">1) &quot;one&quot;</div><div class="line"></div><div class="line">10.200.2.8:7788&gt; sadd myset two</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; scard myset</div><div class="line">(integer) 2</div><div class="line">10.200.2.8:7788&gt; smembers myset</div><div class="line">1) &quot;two&quot;</div><div class="line">2) &quot;one&quot;</div><div class="line"></div><div class="line">//判断集合中是否包含某元素，返回1表示存在</div><div class="line">10.200.2.8:7788&gt; sismember myset &quot;one&quot;</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; sismember myset two</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; sismember myset three</div><div class="line">(integer) 0</div><div class="line"></div><div class="line">//创建新的集合yourset</div><div class="line">10.200.2.8:7788&gt; sadd yourset one</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; sadd yourset three</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; smembers yourset</div><div class="line">1) &quot;three&quot;</div><div class="line">2) &quot;one&quot;</div><div class="line"></div><div class="line">//计算两个集合的并集</div><div class="line">10.200.2.8:7788&gt; sunion myset yourset</div><div class="line">1) &quot;two&quot;</div><div class="line">2) &quot;three&quot;</div><div class="line">3) &quot;one&quot;</div><div class="line">//交集</div><div class="line">10.200.2.8:7788&gt; sinter myset yourset</div><div class="line">1) &quot;one&quot;</div></pre></td></tr></table></figure></p>
<p>对于集合的使用，也有一些常见的方式，比如，QQ有一个社交功能叫做“好友标签”，大家可以给你的好友贴标签，比如“大美女”、“土豪”、“欧巴”等等，这时就可以使用redis的集合来实现，把每一个用户的标签都存储在一个集合之中。集合中不存在重复元素，也可以用于数据查重使用。  </p>
<h3 id="sorted-sets"><a href="#sorted-sets" class="headerlink" title="sorted sets"></a>sorted sets</h3><p>redis不但提供了无需集合（sets），还很体贴的提供了有序集合（sorted sets）。有序集合中的每个元素都关联一个序号（score，权重参数），这便是排序的依据。<br>操作示例：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div></pre></td><td class="code"><pre><div class="line">//新增一个有序集合myzset，并加入一个元素baidu.com，给它赋予的序号是1</div><div class="line">10.200.2.8:7788&gt; zadd myzset 1 baidu.com</div><div class="line">(integer) 1</div><div class="line">//添加元素tencent.com，给它赋予的序号是3</div><div class="line">10.200.2.8:7788&gt; zadd myzset 3 tencent.com</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; zadd myzset 2 google.com</div><div class="line">(integer) 1</div><div class="line">//列出myzset的所有元素，同时列出其序号，可以看出myzset已经是有序的了</div><div class="line">10.200.2.8:7788&gt; zrange myzset 0 -1 withscores</div><div class="line">1) &quot;baidu.com&quot;</div><div class="line">2) &quot;1&quot;</div><div class="line">3) &quot;google.com&quot;</div><div class="line">4) &quot;2&quot;</div><div class="line">5) &quot;tencent.com&quot;</div><div class="line">6) &quot;3&quot;</div><div class="line">10.200.2.8:7788&gt; zrange myzset 0 -1</div><div class="line">1) &quot;baidu.com&quot;</div><div class="line">2) &quot;google.com&quot;</div><div class="line">3) &quot;tencent.com&quot;</div><div class="line">//增加相同权重参数的数据</div><div class="line">10.200.2.8:7788&gt; zadd myzset 2 ericsson.com</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; zrange myzset 0 -1</div><div class="line">1) &quot;baidu.com&quot;</div><div class="line">2) &quot;ericsson.com&quot;</div><div class="line">3) &quot;google.com&quot;</div><div class="line">4) &quot;tencent.com&quot;</div><div class="line">10.200.2.8:7788&gt; zadd myzset 2 alibaba.com</div><div class="line">(integer) 1</div><div class="line">10.200.2.8:7788&gt; zrange myzset 0 -1</div><div class="line">1) &quot;baidu.com&quot;</div><div class="line">2) &quot;alibaba.com&quot;</div><div class="line">3) &quot;ericsson.com&quot;</div><div class="line">4) &quot;google.com&quot;</div><div class="line">5) &quot;tencent.com&quot;</div><div class="line"></div><div class="line">? 相同权重参数的value按字母顺序排列</div></pre></td></tr></table></figure></p>
<p>有序集合非常适用于有序不重复数据的存储，例如游戏开发中无处不在的排行榜，如等级排行榜、经验排行榜、积分排行榜、历史筹码排行榜等。  </p>
<h3 id="hashes"><a href="#hashes" class="headerlink" title="hashes"></a>hashes</h3><p>哈希是从redis-2.0.0版本之后才有的数据结构。hashes存的是字符串和字符串值之间的映射，比如一个用户要存储其全名、姓氏、年龄等等，就很适合使用哈希。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">//建立哈希user:001，并赋值</div><div class="line">10.200.2.8:7788&gt; hmset user:001 username zhangsan passwd zs123 age 20</div><div class="line">OK</div><div class="line">10.200.2.8:7788&gt; hgetall user:001</div><div class="line">1) &quot;username&quot;</div><div class="line">2) &quot;zhangsan&quot;</div><div class="line">3) &quot;passwd&quot;</div><div class="line">4) &quot;zs123&quot;</div><div class="line">5) &quot;age&quot;</div><div class="line">6) &quot;20&quot;</div><div class="line"></div><div class="line">//更改哈希中的某一个值</div><div class="line">10.200.2.8:7788&gt; hset user:001 age 24</div><div class="line">(integer) 0</div><div class="line">10.200.2.8:7788&gt; hgetall user:001</div><div class="line">1) &quot;username&quot;</div><div class="line">2) &quot;zhangsan&quot;</div><div class="line">3) &quot;passwd&quot;</div><div class="line">4) &quot;zs123&quot;</div><div class="line">5) &quot;age&quot;</div><div class="line">6) &quot;24&quot;</div></pre></td></tr></table></figure></p>
<p>更多有关redis命令的操作，可以参考：<strong><a href="http://redis.io/commands" target="_blank" rel="external">点我</a></strong>  </p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/redis/" rel="tag">#redis</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/10/15/hiredis_abc/" rel="prev" title="Hiredis">
                Hiredis <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="LenhartG" />
          <p class="site-author-name" itemprop="name">LenhartG</p>
          <p class="site-description motion-element" itemprop="description">美国《时代周刊》2006年度风云人物</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">38</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">14</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">25</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/gxjares" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/u/2526255830" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  Weibo
                </a>
              </span>
            
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#redis"><span class="nav-number">1.</span> <span class="nav-text">redis</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#redis安装"><span class="nav-number">1.1.</span> <span class="nav-text">redis安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#启动redis"><span class="nav-number">1.2.</span> <span class="nav-text">启动redis</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用redis客户端"><span class="nav-number">1.3.</span> <span class="nav-text">使用redis客户端</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#redis数据结构"><span class="nav-number">1.4.</span> <span class="nav-text">redis数据结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#strings"><span class="nav-number">1.4.1.</span> <span class="nav-text">strings</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#lists"><span class="nav-number">1.4.2.</span> <span class="nav-text">lists</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#sets"><span class="nav-number">1.4.3.</span> <span class="nav-text">sets</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#sorted-sets"><span class="nav-number">1.4.4.</span> <span class="nav-text">sorted sets</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#hashes"><span class="nav-number">1.4.5.</span> <span class="nav-text">hashes</span></a></li></ol></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div>
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="http://music.163.com/outchain/player?type=2&id=208889&auto=1&height=66"></iframe>
</div>
<div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">LenhartG</span>
</div>

<!--
<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>
-->

<!--
<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>
-->
        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  



  




  
  

  

  

  

  


</body>
</html>
